
#include "Msg.h"


/****************屏幕初始化**************/
void screen_init(void)
{
    if (NULL == initscr())
    {
        perror("initscr");
        exit(EXIT_FAILURE);
    }
    /*调用start_color显示色彩*/
    start_color();
    init_pair(1,COLOR_WHITE,COLOR_BLUE);
    init_pair(2,COLOR_BLUE,COLOR_WHITE);
    init_pair(3,COLOR_RED,COLOR_WHITE);
    keypad(stdscr,TRUE); //可在win中接收键盘功能键,会造成段错误？
    //keypad(mainwin,TRUE); //可在win中接收键盘功能键
    //curs_set(0);      //屏蔽物理指针,光标将不会闪烁
    echo();          //设置终端回显

}

/**********************显示接口信息窗口绘制********************/
void infowin_init(WINDOW *infowin, int y, int x)
{
    keypad(infowin,TRUE); //可在win中接收键盘功能键
    box(infowin,0,0);   
    wbkgd(infowin,COLOR_PAIR(2));
    //scrollok(infowin,TRUE);
    //wsetscrreg(infowin, 2, 16);
    //idlok(infowin,TRUE);
    cbreak();
    //wscrl(infowin,4);
    refresh();
    mvwprintw(infowin,1,16, "Interface Message");  
    wattron(infowin,COLOR_PAIR(3));
    wrefresh(infowin);

}


int Info_Display(void)
{
    int y,x;
    
    screen_init();  
    getmaxyx(stdscr,y,x);
    /*创建窗口*/
    if (NULL == (infowin = newwin(LENGTH,WIDTH,y / 7, x / 5)))
    {
        endwin();
        exit(-1);
    }


    /******* 显示接口信息 ***********/
    unsigned int count = 0;
    unsigned int baseline = 3;

    infowin_init(infowin,y,x);          //显示框属性初始化
    for (count = 0; count < if_index; count++)
    {
        if (0 == count)
        {
            mvwprintw(infowin,baseline++,1,g_cur_time);
        }
        mvwprintw(infowin,baseline++,1,szMsg[count].g_if_name);   //将内容打印到窗口
        mvwprintw(infowin,baseline++,1,szMsg[count].g_tx_packets);  
        mvwprintw(infowin,baseline++,1,szMsg[count].g_rx_packets);
        mvwprintw(infowin,baseline++,1,szMsg[count].g_tx_bytes);
        mvwprintw(infowin,baseline++,1,szMsg[count].g_rx_bytes);
    }
    
    wrefresh(infowin);
    sleep(1);   //停留1s再刷新
    werase(infowin);          //清除窗口内容
    //}


    return 0;
}

